package com.umeng.analytics.pro;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.concurrent.atomic.AtomicInteger;

public class b {
    private AtomicInteger a;
    private AtomicInteger b;
    private static b c;
    private static SQLiteOpenHelper d;
    private SQLiteDatabase e;

    public b() {

        this.a = new AtomicInteger();
        this.b = new AtomicInteger();
    }

    public static b a(Context arg2) {
        b v0_1;
        Class v1 = b.class;
        synchronized (v1) {
            if (c == null) {
                b(arg2);
            }

            v0_1 = c;
        }
        return v0_1;
    }

    public SQLiteDatabase a() {
        SQLiteDatabase v0_1;
        synchronized (this) {
            if (this.a.incrementAndGet() == 1) {
                this.e = d.getReadableDatabase();
            }

            v0_1 = this.e;
        }
        return v0_1;
    }

    private static void b(Context arg2) {
        Class v1 = b.class;
        synchronized (v1) {
            if (c == null) {
                c = new b();
                d = com.umeng.analytics.pro.c.a(arg2);
            }
        }
    }

    public SQLiteDatabase b() {
        SQLiteDatabase v0_1;
        synchronized (this) {
            if (this.a.incrementAndGet() == 1) {
                this.e = d.getWritableDatabase();
            }

            v0_1 = this.e;
        }
        return v0_1;
    }

    public void c() {
        synchronized (this) {
            if (this.a.decrementAndGet() == 0) {
                this.e.close();
            }

            if (this.b.decrementAndGet() == 0) {
                this.e.close();
            }
        }
    }
}

